package com.dqp.cslggroup;

import android.annotation.SuppressLint;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dqp.cslggroup.UI.MyApplication;
import com.dqp.cslggroup.Util.GetTimeUtil;
import com.dqp.cslggroup.bean.student;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class Fragment_Three extends Fragment {
    private RecyclerView mRecyclerView;
    private String cntDateBeg;
    private String cntDateEnd;
    private int sumDay;

    @SuppressLint("InflateParams")
    @Override

    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.photo_viewpager_layout, null);
        mRecyclerView = view.findViewById(R.id.rec2);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(layoutManager);
        initList();
        return view;
    }

    @SuppressLint("HandlerLeak")
    private void initList() {
        ArrayList<String> dataList = new ArrayList<>();
        List<student> studentList=MyApplication.getDaoInstant().getStudentDao().loadAll();
        if (studentList.size()>0) {
            student student=studentList.get(0);
            String xm = student.getXm();
            String rxnf = student.getRxnf();
            if (rxnf.contains("2016")) {
                cntDateBeg = "2016-09-09";
            } else if (rxnf.contains("2017")) {
                cntDateBeg = "2017-09-09";
            } else if (rxnf.contains("2018")) {
                cntDateBeg = "2018-09-09";
            } else if (rxnf.contains("2019")) {
                cntDateBeg = "2019-09-02";
            }
            else if (rxnf.contains("2020")) {
                cntDateBeg = "2020-09-10";
            }else if (rxnf.contains("2021")) {
                cntDateBeg = "2021-08-03";
            }
            Date d = new Date();
            @SuppressLint("SimpleDateFormat") DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            cntDateEnd = df.format(d);
            sumDay = GetTimeUtil.addDates(cntDateBeg, cntDateEnd);
            dataList.add(0, "来到常熟理工的");
            dataList.add(1, "第" + sumDay + "天");
            Adapter_Diary mAdapter = new Adapter_Diary(dataList);
            mRecyclerView.setAdapter(mAdapter);
        }
    }


}
